<%-- 
    Document   : index
    Created on : Mar 24, 2014, 11:07:20 AM
    Author     : Mona
--%>

<%@ include file="headerAdmin.jsp" %>
<script>
    function validateProduct()
    {
        var name = document.forms["add"]["name"].value;
        var regexName = /^[a-zA-Z0-9\s]+$/;
        if (!regexName.test(name))
        {
            alert("Name should not contain special character");
            document.add.name.focus();
            return false;
        }
        var description = document.forms["add"]["description"].value;
        var regexName = /^[a-zA-Z0-9\s\,\\]+$/;
        if (!regexName.test(name))
        {
            alert("Name should not contain special character");
            document.add.description.focus();
            return false;
        }
        var fuData = document.getElementById('image');
        var FileUploadPath = fuData.value;
        if (FileUploadPath != '') {
            var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();
            //alert(Extension);
            if (Extension != "gif" && Extension != "png" && Extension != "bmp" && Extension != "jpeg" && Extension != "jpg") {
                alert("Photo only allows file types of GIF, PNG, JPG, JPEG and BMP. ");
                document.add.image.focus();
                return false;
            }
        }
        var quantity= document.forms["add"]["quantity"].value;
        var regexQuantity=/^\d{1,6}$/;
        if(!regexQuantity.test(quantity))
        {
            alert("Quantity should be decimal number");
            document.add.quantity.focus();
            return false;
        }
        var price = document.forms["add"]["price"].value;
        var regexPrice = /^\d*\.?\d*$/;
        if(!regexPrice.test(price))
        {
            alert("Price can be float or integer number ");
            document.add.price.focus();
            return false;
        }
    }
</script>
<div class="top_bg">
    <div class="wrap">
        <div class="main_top">
            <h2 class="style">Add Product</h2>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-6" style="margin-left: 60px;margin-top: 20px">
            <div class="main_top">
                <form action="AddProduct" name="add" method="POST" onsubmit="return validateProduct()" role="form" enctype="multipart/form-data"  >
                    <div class="form-group">
                        <label for="name">Name:</label><br>
                        <input class="form-control" type="text" name="name" required/> <br>
                    </div>
                    <div class="form-group">
                        <label for="description">Description:</label><br>
                        <textarea class="form-control" name="description" required></textarea> <br>     
                    </div>
                    <div class="form-group">
                        <label for="quantity">Quantity:</label><br>
                        <input class="form-control" type="number" required name="quantity" /> <br>
                    </div>
                    <div class="form-group">
                        <label for="price">Price:</label><br>
                        <input class="form-control" type="text" required name="price" /> <br>
                    </div>

                    <sql:query dataSource="${conn}" var="result">
                        SELECT id,catName from Category;
                    </sql:query>
                    <div class="form-group">
                        <label for="category">Categories:</label><br>
                        <select name="categoryId" required>
                            <c:forEach var="row" items="${result.rows}">
                                <option name="categoryId" value="<c:out value="${row.id}"/>">
                                    <c:out value="${row.catName}"/>
                                </option>
                            </c:forEach>
                        </select> <br>
                    </div> 
                    <div class="form-group">
                        <label for="image">Image:</label><br>
                        <input type="file" id="image" required name="image" /> <br>
                    </div>
                    <div class="form-group">
                        <button type="submit" class="btn btn-success" />Submit</button> <br>
                    </div>


                </form>
            </div>
        </div>
    </div>
</div>
<%@include file="footer.jsp" %>
